import React, { Component } from 'react';

const Layout = () => <div>Layout</div>;

const Login = (props) => {
    const login = () => {
        props.callback && props.callback(true);
    };
    return (
        <div>
            <h2>Login</h2>
            <div>用户名: <input type="text" /></div>
            <div>密码: <input type="text" /></div>
            <button onClick={login}>登录</button>
        </div>
    );
};

export default class Parent extends Component {
    state = {
        isLogin: false
    }

    render () {
        return (
            <div>
                {
                    this.state.isLogin
                        ? (
                            <Layout />
                        )
                        : (
                            <Login callback={(isLogin) => this.setState({ isLogin })} />
                        )
                }
            </div>
        );
    }
}
